package com.example.yrdev.ordering_system.CustomView;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

import com.example.yrdev.ordering_system.Model.Good;
import com.example.yrdev.ordering_system.R;
import com.example.yrdev.ordering_system.Utils.GlobalFunction;

/**
 * Created by yrdev on 8/31/16.
 */
public class GoodsTableView extends Fragment{
    public Context context;
    public GoodsTableView(){

    }

    @SuppressLint("ValidFragment")
    public GoodsTableView(Context context){
    this.context=context;

    }

   public TableLayout tableLayout;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        tableLayout=new TableLayout(this.context);
        tableLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        tableLayout.setOrientation(LinearLayout.HORIZONTAL);
        tableLayout.setBackgroundColor(ContextCompat.getColor(this.context, R.color.colorAccent));

//        Good goods=new Good();
//        goods.setName("苹果");
//        goods.setId("001");
//        goods.setItemNo("001");
////        goods.setMemberPrice("1元");
////        goods.setRetailPrice("2元");
//        addGoods(goods);
       return tableLayout;

    }
    public  void addGoods(Good goods){
        TableRow tableRow=new TableRow(this.context);
        tableRow.setOrientation(LinearLayout.HORIZONTAL);

        TextView itemNo=new TextView(this.context);
        itemNo.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT, 1.f));
        itemNo.setText(goods.getId());
        itemNo.setGravity(Gravity.CENTER_HORIZONTAL);
        itemNo.setTextSize(18);
        tableRow.addView(itemNo);

        TextView itemName=new TextView(this.context);
        itemName.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT,1.f));
        itemName.setText(goods.getName());
        itemName.setGravity(Gravity.CENTER_HORIZONTAL);
        itemName.setTextSize(18);
        tableRow.addView(itemName);


        TextView retailPrice=new TextView(this.context);
        retailPrice.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT,1.f));
        retailPrice.setText(goods.getPriceIn());
        retailPrice.setGravity(Gravity.CENTER_HORIZONTAL);
        retailPrice.setTextSize(18);
        tableRow.addView(retailPrice);

        TextView memberPrice=new TextView(this.context);
        memberPrice.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT,1.f));
        memberPrice.setText(goods.getPriceOut());
        memberPrice.setGravity(Gravity.CENTER_HORIZONTAL);
        memberPrice.setTextSize(18);
        tableRow.addView(memberPrice);

        GlobalFunction.printText("tag", "2dasdsad");
        if (tableLayout!=null){

        }
        this.tableLayout.addView(tableRow,new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT));
       // tableLayout.addView(tableRow);

    }



}
